import { asyncRoutes, constantRoutes } from '@/router'
const state = {
  routes: []
}

const mutations = {
  setRoutes(state, payload) {
    state.routes = [...payload,
      ...constantRoutes
    ]
  }
}

const actions = {
  filterRoutes(context, menus) {
    // console.log('拿到权限列表', menus)
    // console.log('拿到权限全部数据', asyncRoutes)
    const arr = []
    asyncRoutes.forEach(inem => {
      if (menus.indexOf(inem.name) !== -1) {
        arr.push(inem)
      }
    })
    context.commit('setRoutes', arr)
    // console.log('权限', arr)
    // 返回
    return arr
  }
}

// 暴露
export default {
  state,
  mutations,
  actions,
  namespaced: true
}
